<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改素材信息')"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-material-edit" th:object="${cmsMaterial}">
        <input name="materialId" th:field="*{materialId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>所属商户：</label>
            <div class="col-sm-8">
                <select id="merchantId" class="form-control" name="merchantId">
                    <option value="">----系统商户----</option>
                    <option th:each="post:${mts}"
                            th:value="${post.merchantId}"
                            th:text="${post.merchantName}" th:field="*{merchantId}"></option>
                </select></li>                </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>分组id：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input id="treeId" name="groupId" class="form-control" required type="hidden" th:field="*{groupId}">
                    <input placeholder="请选择分组" th:field="*{groupName}" class="form-control" required type="text"
                           onclick="selectMaterialGroupTree()" id="treeName"
                           readonly="true">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>素材名称：</label>
            <div class="col-sm-8">
                <input name="materialName" th:field="*{materialName}" class="form-control" type="text" required
                       maxlength="20">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label"><span style="color: red; ">*</span>素材类型：</label>
            <div class="col-sm-8">
                <select name="materialType" class="form-control m-b"
                        th:with="type=${@dict.getType('csm_material_type')}" required>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
                            th:field="*{materialType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">素材描述：</label>
            <div class="col-sm-8">
                <input name="materialDescription" th:field="*{materialDescription}" class="form-control" type="text"
                       maxlength="20">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">可用状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sms_use_state')}">
                    <input type="radio" th:id="${'useState_' + dict.dictCode}" name="useState"
                           th:value="${dict.dictValue}" th:field="*{useState}">
                    <label th:for="${'useState_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">素材图片：</label>
            <div class="col-sm-8">
                <div class="file-loading">
                    <input class="file" type="file" multiple data-min-file-count="1"
                           accept="image/*" data-theme="fas" id="pic_file" name="pic_file">
                </div>
                <span class="help-block m-b-none"><i
                        class="fa fa-info-circle"></i> 提示：请上传16:9或4:3常用比例图片，否则会影响用户体验</span>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script type="text/javascript">
    var img = '[[${cmsMaterial.savePath}]]';
    $("#pic_file")
        .fileinput(
            {
                initialPreview: [ //预览图片的设置
                    '<img src="'
                    + ctx + "profile" + img
                    + '" alt="素材图片" class="file-preview-image" style="width:auto;height:auto;max-width:100%;max-height:100%;">']
            });

    var prefix = ctx + "bussiness_cms/material";
    $("#form-material-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            var formdata = new FormData(document.getElementById("form-material-edit"));
            $.operate.saveImg(prefix + "/edit", formdata);
        }
    }

    /*素材分组-新增-选择父部门树*/
    function selectMaterialGroupTree() {
        var options = {
            title: '素材组别择',
            width: "380",
            url: ctx + "bussiness_cms/materialgroup" + "/selectMaterialGroupTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }

</script>
</body>
</html>